<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Model\Aboot\Wechat;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

class WeChatController extends Controller
{
    public function index()
    {
        dd('开发中...');
        $wcs = Wechat::first();
        return view('admin.setting.wechat', compact('wcs'));
    }

    public function store(Request $request)
    {
        dd('开发中...');

        $token = md5(time());
        $encodingaeskey = md5(microtime(true));
        $wc = Wechat::find(1);
        $wc = $wc ? $wc : Wechat::create(['webname'=>request()->webname,'account'=>request()->webname,'appid'=>request()->appid,'appsecret'=>request()->appsecret,'token'=>$token,'encodingaeskey'=>$encodingaeskey]);
        $wc->update(['webname'=>request()->webname,'account'=>request()->webname,'appid'=>request()->appid,'appsecret'=>request()->appsecret,'token'=>$token,'encodingaeskey'=>$encodingaeskey]);
        config('wechat.token', $token);
        return back();
    }
}
